package com.ruoyi.degree.service.Impl;

import java.util.*;
import java.util.stream.Collectors;

import com.ruoyi.degree.domain.BizSchoolsProfessions;
import com.ruoyi.degree.mapper.BizSchoolsProfessionsMapper;
import com.ruoyi.degree.service.IBizSchoolsProfessionsService;
import com.ruoyi.degree.service.IBizSchoolsVideosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.degree.mapper.BizSchoolsMapper;
import com.ruoyi.degree.domain.BizSchools;
import com.ruoyi.degree.service.IBizSchoolsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 大学信息列表展示Service业务层处理
 *
 * @author ruoyi
 * @date 2025-07-24
 */
@Service
public class BizSchoolsServiceImpl implements IBizSchoolsService
{
    @Autowired
    private BizSchoolsMapper bizSchoolsMapper;
    @Autowired
    private IBizSchoolsProfessionsService bizSchoolsProfessionsService;
    @Autowired
    private IBizSchoolsVideosService bizSchoolsVideosService;
    @Autowired
    private BizSchoolsProfessionsMapper bizSchoolsProfessionsMapper;


    /**
     * 查询大学信息列表展示
     *
     * @param id 大学信息列表展示主键
     * @return 大学信息列表展示
     */
    @Override
    public BizSchools selectBizSchoolsById(Long id)
    {
        return bizSchoolsMapper.selectBizSchoolsById(id);
    }

    /**
     * 查询大学信息列表展示列表
     *
     * @param bizSchools 大学信息列表展示
     * @return 大学信息列表展示
     */

    // BizSchoolsServiceImpl.java
    @Override
    public List<BizSchools> selectBizSchoolsList(BizSchools bizSchools) {
        return bizSchoolsMapper.selectBizSchoolsList(bizSchools);
    }



    /**
     * 新增大学信息列表展示
     *
     * @param bizSchools 大学信息列表展示
     * @return 结果
     */
    @Override
    public int insertBizSchools(BizSchools bizSchools) {
        // 核心逻辑：自动截取pics的第一个照片地址给logo
        String pics = bizSchools.getPics();
        if (pics != null && !pics.isEmpty()) {
            // 分割后取第一个元素（处理多图情况）
            String logo = pics.split(",")[0];
            bizSchools.setLogo(logo);
        } else {
            // 处理pics为空的情况，避免logo为null
            bizSchools.setLogo("");
        }
        // 原有插入逻辑不变
        return bizSchoolsMapper.insertBizSchools(bizSchools);
    }

    /**
     * 修改大学信息列表展示
     *
     * @param bizSchools 大学信息列表展示
     * @return 结果
     */
    @Override
    public int updateBizSchools(BizSchools bizSchools)
    {
        return bizSchoolsMapper.updateBizSchools(bizSchools);
    }

    /**
     * 批量删除大学信息列表展示
     *
     * @param ids 需要删除的大学信息列表展示主键
     * @return 结果
     */
    @Override
    public int deleteBizSchoolsByIds(Long[] ids)
    {
        bizSchoolsProfessionsService.deleteBizSchoolsProfessionsBySchoolIds(ids);
        bizSchoolsVideosService.deleteBizSchoolsVideosBySchoolIds(ids);

        return bizSchoolsMapper.deleteBizSchoolsByIds(ids);
    }

    /**
     * 删除大学信息列表展示信息
     *
     * @param id 大学信息列表展示主键
     * @return 结果
     */
    @Override
    public int deleteBizSchoolsById(Long id)
    {
        return bizSchoolsMapper.deleteBizSchoolsById(id);
    }

    @Override
    public int toggleHot(Long id) {
        BizSchools school = bizSchoolsMapper.selectBizSchoolsById(id);
        school.setIsHot("1".equals(school.getIsHot()) ? "0" : "1");
        return bizSchoolsMapper.updateBizSchools(school);
    }

    @Override
    public int toggleShow(Long id) {
        BizSchools school = bizSchoolsMapper.selectBizSchoolsById(id);
        school.setIsShow(Long.valueOf(1).equals(school.getIsShow()) ? 0L : 1L);
        return bizSchoolsMapper.updateBizSchools(school);
    }

    // BizSchoolsServiceImpl.java
    @Override
    public List<BizSchools> selectSchoolsByPlaceAndPlanAndDate(Long placeId, Long eduPlanId, List<String> openingDateIdList, String openingDates, int offset, int pageSize) {
        return bizSchoolsMapper.selectSchoolsByPlaceAndPlanAndDate(placeId, eduPlanId, openingDateIdList, openingDates, offset, pageSize);
    }
    @Override
    public List<Long> selectEduPlanIdByPlaceId(Long PlaceId) {
        return bizSchoolsMapper.selectEduPlanIdByPlaceId(PlaceId);
    }


}
